package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.dummy.DummyContent;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

public class MainActivity extends AppCompatActivity implements ItemFragment.OnListFragmentInteractionListener{


    private EditText editText;
    private EditText editText2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

    }

    public void testGetRequest(View view) throws ExecutionException, InterruptedException {
        System.out.println(OkHttpUtil.getRequest("https://www.baidu.com"));
    }

    public void testPostRequest(View view) throws ExecutionException, InterruptedException {
        Map<String, String> map = new HashMap<>();
        map.put("username", editText.getText().toString());
        map.put("userpass", editText2.getText().toString());
        String result = OkHttpUtil.postRequest(
                "http://172.18.85.254:8080/auction/api/users/login", map);

        if (result != null && result.equals("1")){
            Intent intent =
                    new Intent(this,IndexActivity.class);
           startActivity(intent);
        }else {
            Toast.makeText(this,"登录失败",Toast.LENGTH_LONG).show();
        }
    }


    private void initView() {
        editText = (EditText) findViewById(R.id.editText);
        editText2 = (EditText) findViewById(R.id.editText2);
    }


    @Override
    public void onListFragmentInteraction(DummyContent.DummyItem item) {

    }
}
